package com.xbongbong.saas.service.impl;

import com.xbongbong.paas.elasticsearch.util.EsHelper;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.invoicerelation.pojo.dto.InvoiceRelationshipDeleteBatchDTO;
import com.xbongbong.pro.invoicerelation.pojo.vo.InvoiceRelationshipDeleteBatchVO;
import com.xbongbong.saas.model.InvoiceRelationshipModel;
import com.xbongbong.saas.service.InvoiceRelationshipService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 吴峰
 * @version v1.0
 * @date 2019/3/12 19:11
 * @since v1.0
 */
@Service("invoiceRelationService")
public class InvoiceRelationshipServiceImpl implements InvoiceRelationshipService {

    private static final Logger LOG = LoggerFactory.getLogger(InvoiceRelationshipServiceImpl.class);

    @Resource
    private InvoiceRelationshipModel invoiceRelationshipModel;
    @Resource
    private EsHelper esHelper;

    @Override
    public InvoiceRelationshipDeleteBatchVO deleteBatchByInvoiceIdIn(InvoiceRelationshipDeleteBatchDTO invoiceRelationshipDeleteBatchDTO) throws XbbException {
        InvoiceRelationshipDeleteBatchVO invoiceRelationshipDeleteBatchVO = new InvoiceRelationshipDeleteBatchVO();
        try {
            List<Long> invoiceIdIn = invoiceRelationshipDeleteBatchDTO.getInvoiceIdIn();
            String corpid = invoiceRelationshipDeleteBatchDTO.getCorpid();
            invoiceRelationshipModel.deleteByInvoiceIdIn(invoiceIdIn, corpid);
        } catch (Exception e) {
            LOG.error("invoiceRelationService.deleteBatchByInvoiceIdIn 执行出错", e);
            throw new XbbException(SystemErrorCodeEnum.API_ERROR_100001, SystemErrorCodeEnum.API_ERROR_100001.getMsg());
        }
        return invoiceRelationshipDeleteBatchVO;
    }
}
